#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Author:Taotie Ren
# import logging

# 禁用日志模块
# logging.disable(logging.CRITICAL)
# logging.basicConfig(level=logging.DEBUG, format=' %(asctime)s - %(levelname)s - %(message)s')

# lucky.py - Opens several Google seacrh results.
import requests, sys, webbrowser, bs4

print('Googling...')  # display text while downloading the google page.
res = requests.get('http://google.com/search?q=' + ' '.join(sys.argv[1:]))
res.raise_for_status()

# Retrieve top search result links
soup = bs4.BeautifulSoup(res.text)

# Open a browser tab for each result.
linkElems = soup.select('.r a')
numOpen = min(5, len(linkElems))
for i in range(numOpen):
	webbrowser.open('http://google.com' + linkElems[i].get('href'))
